import Vue from 'vue'
import App from './App'
import store from './store'
import utils from '@/utils'
import { syncVars, syncVarReady, syncVarCallback } from '@/env'
import { router, RouterMount } from './router' // 路径换成自己的
import BaseHeader from '@/components/BaseHeader.vue'
Vue.component('BaseHeader', BaseHeader) // 分类
Vue.use(router)
Vue.config.productionTip = false
Vue.prototype.$store = store
Vue.prototype.$f = utils

// 设置全局同步变量
syncVars.forEach(name => {
  const readyName = syncVarReady(name)
  const callbackName = syncVarCallback(name)
  Vue.prototype[readyName] = () => new Promise((resolve) => {
    const data = store.state[name]
    if (utils.isEmpty(data)) {
      Vue[callbackName] = res => {
        return resolve(res)
      }
    } else {
      return resolve(data)
    }
  })
})

App.mpType = 'app'

const app = new Vue({
  store,
  ...App
})
// #ifdef H5
RouterMount(app, router, '#app')
// #endif

// #ifndef H5
app.$mount() // 为了兼容小程序及app端必须这样写才有效果
// #endif
